#ifndef _LIST_H
#define _LIST_H

struct List
{
        struct List * prev;
        struct List * next;
};

static inline void list_init(struct List * list)
{
        list->prev = list;
        list->next = list;
}

static inline void list_add_to_behind(struct List * entry,struct List * new)   ////add to entry behind
{
        new->next = entry->next;
        new->prev = entry;
        new->next->prev = new;
        entry->next = new;
}

static inline void list_add_to_before(struct List * entry,struct List * new)   ////add to entry behind
{
        new->next = entry;
        entry->prev->next = new;
        new->prev = entry->prev;
        entry->prev = new;
}

static inline void list_del(struct List * entry)
{
        entry->next->prev = entry->prev;
        entry->prev->next = entry->next;
}

static inline long list_is_empty(struct List * entry)
{
        if(entry == entry->next && entry->prev == entry)
                return 1;
        else
                return 0;
}

static inline struct List * list_prev(struct List * entry)
{
        if(entry->prev != NULL)
                return entry->prev;
        else
                return NULL;
}

static inline struct List * list_next(struct List * entry)
{
        if(entry->next != NULL)
                return entry->next;
        else
                return NULL;
}

#endif /* _LIST_H */
